﻿using System;

namespace BridgePattern;

//桥接模式

// 抽象类：电视
public abstract class Tv(RemoteControl remoteControl)
{
    protected readonly RemoteControl RemoteControl = remoteControl;
    public abstract void TurnOn();
    public abstract void TurnOff();
}

// 具体实现：Sony电视
public class SonyTv(RemoteControl remoteControl) : Tv(remoteControl)
{
    public override void TurnOn()
    {
        Console.WriteLine("Sony TV is on.");
        RemoteControl.PressPower();
    }

    public override void TurnOff()
    {
        Console.WriteLine("Sony TV is off.");
        RemoteControl.PressPower();
    }
}

// 具体实现：Panasonic电视
public class SamsungTv(RemoteControl remoteControl) : Tv(remoteControl)
{
    public override void TurnOn()
    {
        Console.WriteLine("Panasonic TV is on.");
        RemoteControl.PressPower();
    }

    public override void TurnOff()
    {
        Console.WriteLine("Panasonic TV is off.");
        RemoteControl.PressPower();
    }
}

// 抽象类：遥控器
public abstract class RemoteControl
{
    public abstract void PressPower();
}

// 具体实现：红外遥控器
public class InfraredRemote : RemoteControl
{
    public override void PressPower()
    {
        Console.WriteLine("Infrared signal sent.");
    }
}

// 具体实现：蓝牙遥控器
public class BluetoothRemote : RemoteControl
{
    public override void PressPower()
    {
        Console.WriteLine("Bluetooth signal sent.");
    }
}

// 客户端代码
public static class Program
{
    public static void Main()
    {
        // 创建Sony电视并使用红外遥控器
        RemoteControl infraredRemote = new InfraredRemote();
        Tv sonyTv = new SonyTv(infraredRemote);
        sonyTv.TurnOn();
        sonyTv.TurnOff();

        // 创建Panasonic电视并使用蓝牙遥控器
        RemoteControl bluetoothRemote = new BluetoothRemote();
        Tv samsungTv = new SamsungTv(bluetoothRemote);
        samsungTv.TurnOn();
        samsungTv.TurnOff();
    }
}